package com.ruoyi.web.controller.construction;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.construction.ConstructionComment;

import com.ruoyi.system.service.construction.ConstructionCommentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 施工队评论Controller
 * 
 * @author 张少丛
 * @date 2020-11-04
 */
@RestController
@RequestMapping("/construction/comment")
public class ConstructionCommentController extends BaseController
{
    @Autowired
    private ConstructionCommentService constructionCommentService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询施工队评论列表
     */
    @PreAuthorize("@ss.hasPermi('construction:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConstructionComment constructionComment)
    {
        // 开启分页
        startPage();
        // 获取登录用户ID
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long userId = loginUser.getUser().getUserId();
        // 多条件查询施工队评论信息
        List<ConstructionComment> list = constructionCommentService.selectConstructionCommentList(constructionComment,userId);
        return getDataTable(list);
    }

    /**
     * 导出施工队评论列表
     */
    @PreAuthorize("@ss.hasPermi('construction:comment:export')")
    @Log(title = "施工队评论", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ConstructionComment constructionComment)
    {
        // 获取登录用户ID
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long userId = loginUser.getUser().getUserId();
        List<ConstructionComment> list = constructionCommentService.selectConstructionCommentList(constructionComment,userId);
        ExcelUtil<ConstructionComment> util = new ExcelUtil<ConstructionComment>(ConstructionComment.class);
        return util.exportExcel(list, "comment");
    }

    /**
     * 获取施工队评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('construction:comment:query')")
    @GetMapping(value = "/{constructionCommId}")
    public AjaxResult getInfo(@PathVariable("constructionCommId") Integer constructionCommId)
    {
        return AjaxResult.success(constructionCommentService.selectConstructionCommentById(constructionCommId));
    }

    /**
     * 新增施工队评论
     */
    @PreAuthorize("@ss.hasPermi('construction:comment:add')")
    @Log(title = "施工队评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConstructionComment constructionComment)
    {
        return toAjax(constructionCommentService.insertConstructionComment(constructionComment));
    }

    /**
     * 修改施工队评论
     */
    @PreAuthorize("@ss.hasPermi('construction:comment:edit')")
    @Log(title = "施工队评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConstructionComment constructionComment)
    {
        return toAjax(constructionCommentService.updateConstructionComment(constructionComment));
    }

    /**
     * 删除施工队评论
     */
    @PreAuthorize("@ss.hasPermi('construction:comment:remove')")
    @Log(title = "施工队评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{constructionCommIds}")
    public AjaxResult remove(@PathVariable Integer[] constructionCommIds)
    {
        return toAjax(constructionCommentService.deleteConstructionCommentByIds(constructionCommIds));
    }

    /**
     * 修改评论的审核状态
     * @param constructionComment
     * @return
     */
    @PreAuthorize("@ss.hasPermi('construction:comment:edit')")
    @Log(title = "施工队评论", businessType = BusinessType.UPDATE)
    @PutMapping("/changeCommentStatus")
    public AjaxResult changeCommentStatus(@RequestBody ConstructionComment constructionComment){
        return toAjax(constructionCommentService.changeCommentStatus(constructionComment));
    }
}
